<template>
	<view class="tabbar">
		<view class="navigator">
			<view class="navigator-item" v-for="(item,index) in tabBar.list" :key="item.pagePath"
				@click="switchTab(index,item)">
				<image :src="imgHost+item.iconPath" class="icon" v-if="selectedIndex !== index"></image>
				<image :src="imgHost+item.selectedIconPath" class="icon" v-else></image>
				<text :class="['item-text',{'text-active':selectedIndex === index}]">{{item.text}}</text>
			</view>
		</view>
	</view>
	</view>

</template>
<script>
	import {
		HTTP_REQUEST_URL
	} from '@/config/app.js';
	export default {
		props: [
			'current'
		],
		data() {
			return {
				imgHost: HTTP_REQUEST_URL + '/mingpian',
				selectedIndex: this.current,
				showselected: false,
				tabBar: {
					list: [{
						"pagePath": "/pages/index/minp",
						"iconPath": "/taber/indexselect.png",
						"selectedIconPath": "/taber/indexicon.png",
						"text": "名片"
					}, {
						"pagePath": "/pages/userminp/mine/mpjia/mpjia",
						"iconPath": "/taber/mineselect.png",
						"selectedIconPath": "/taber/mineicon.png",
						"text": "我的"
					}]
				},
			}
		},
		methods: {
			switchTab(index, item) {
				console.log(item);
				uni.redirectTo({
					url: item.pagePath
				})
				let url = '/' + item.pagePath
				let pagePath = url
				const detail = {
					index,
					pagePath
				}
				if (this.$route.path !== url) {
					uni.switchTab({
						from: 'tabBar',
						url,
						detail
					})
				} else {}
				this.selectedIndex = index
			}
		},
	}
</script>

<style lang="scss">
	.tabbar {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		z-index: 999;
		background: #fff;
		// border-top: 2rpx solid #eee;
		padding: 0rpx 90rpx;
	}

	.navigator {
		display: flex;
		justify-content: space-between;
		width: 85%;
		margin: 0 auto;
		padding: 20rpx;
	}

	.navigator-item {
		display: flex;
		align-items: center;
		flex-direction: column;
		width: 50rpx;
		height: 100%;
	}

	.item-text {
		margin-top: 6rpx;
		color: #777E86;
		font-size: 24rpx;
	}

	.text-active {
		color: #E33C21 !important;
	}

	.icon {
		width: 20px;
		height: 20px;
	}
</style>
